Sha256: b58bd11fa5afd6ae0a45ff052f976e361578646d0b394cf4cc2c4471befdcb7d

Contents?: true

Size: 945 Bytes

Versions: 1

Compression:

Stored size: 945 Bytes

Contents

# frozen_string_literal: true

require 'ditty/controllers/component'
require 'proxes/models/permission'
require 'proxes/policies/permission_policy'

module ProxES
  class Permissions < Ditty::Component
    set model_class: Permission

    FILTERS = [
      { name: :user, field: 'user.email' },
      { name: :role, field: 'role.name' },
      { name: :verb }
    ].freeze

    SEARCHABLE = %i[pattern]

    helpers do
      def user_options
        policy_scope(::Ditty::User).as_hash(:email, :email)
      end

      def role_options
        policy_scope(::Ditty::Role).as_hash(:name, :name)
      end

      def verb_options
        ProxES::Permission.verbs
      end
    end

    def find_template(views, name, engine, &block)
      super(views, name, engine, &block) # Root
      super(::Ditty::ProxES.view_folder, name, engine, &block) # This Component
      super(::Ditty::App.view_folder, name, engine, &block) # Ditty
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
proxes-0.8.3 lib/proxes/controllers/permissions.rb