Sha256: 206d91ac419504c37b84c270aaad418b02c8e4fd1cc61362f50c2cc208c1f454

Contents?: true

Size: 984 Bytes

Versions: 2

Compression:

Stored size: 984 Bytes

Contents

module Eaco
  module Adapters
    module ActiveRecord

      ##
      # Authorized collection extractor on PostgreSQL >= 9.4 and a +jsonb+
      # column named +acl+.
      #
      # TODO negative authorizations (using a separate column?)
      #
      # @see ACL
      # @see Actor
      # @see Resource
      #
      module PostgresJSONb

        ##
        # Uses the json key existance operator +?|+ to check whether one of the
        # +Actor+'s +Designator+ instances exist as keys in the +ACL+ objects.
        #
        # @param actor [Actor]
        #
        # @return [ActiveRecord::Relation] the authorized collection scope.
        #
        def accessible_by(actor)
          return scoped if actor.is_admin?

          designators = actor.designators.map {|d| quote_value(d, nil) }

          column = "#{connection.quote_table_name(table_name)}.acl"

          where("#{column} ?| array[#{designators.join(',')}]::varchar[]")
        end
      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eaco-1.0.0 lib/eaco/adapters/active_record/postgres_jsonb.rb
eaco-0.8.2 lib/eaco/adapters/active_record/postgres_jsonb.rb