Sha256: 8b20fd33f0d7c8077c8194ca7be11b05ddc474282abbd495b1bbf0a28a2933ed

Contents?: true

Size: 893 Bytes

Versions: 2

Compression:

Stored size: 893 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) }

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

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
eaco-0.6.0 lib/eaco/adapters/active_record/postgres_jsonb.rb
eaco-0.5.0 lib/eaco/adapters/active_record/postgres_jsonb.rb