Sha256: ba1bfab775011409820262d0189ab740ce406964dee4fdb7769fabb9883d2884

Contents?: true

Size: 1.15 KB

Versions: 37

Compression:

Stored size: 1.15 KB

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_handlers, Hash
      attribute :authorization_handlers_options, Hash

      def authorization_handlers_names
        authorization_handlers.keys.map(&:to_s)
      end

      def authorization_handler_options(handler_name)
        find_handler(handler_name)&.dig("options") || {}
      end

      def manifest(handler_name)
        Decidim::Verifications.find_workflow_manifest(handler_name)
      end

      def options_schema(handler_name)
        options_manifest(handler_name).schema.new(authorization_handler_options(handler_name))
      end

      def options_attributes(handler_name)
        manifest = options_manifest(handler_name)
        manifest ? manifest.attributes : []
      end

      private

      def options_manifest(handler_name)
        manifest(handler_name).options
      end

      def find_handler(handler_name)
        authorization_handlers[handler_name.to_s] ||
          authorization_handlers[handler_name.to_sym]
      end
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
decidim-admin-0.23.6 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.24.2 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.23.5 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.24.1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.24.0 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.24.0.rc2 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.23.4 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.24.0.rc1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.23.3 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.23.2 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.23.1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.23.1.rc1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.23.0 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.22.0 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.21.0 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.20.1 app/forms/decidim/admin/permission_form.rb
decidim-admin-0.20.0 app/forms/decidim/admin/permission_form.rb