Sha256: ca9e52cf1bf47e9573a1231d9eba44b9ec3a640e0319583a9de91d102c8a26a0

Contents?: true

Size: 752 Bytes

Versions: 14

Compression:

Stored size: 752 Bytes

Contents

require 'vigilante/watched_operator'

module Vigilante
  module ActiveRecordExtensions

    def self.included(base)
      base.extend ClassMethods
    end

    module ClassMethods

      def accessible_extent(user)
        extent = user.permits.get_extent_of(self.name.underscore.pluralize, :show)
        if extent.include?('*')
          nil
        else
          # fix: if extent is empty return 0 which would can be used in sql and not match anything
          extent.size == 0 ? '0' : extent.join(',')
        end
      end

      # run this in the model that is the operator or user or ...
      def authorisations_handled_by_vigilante
        module_eval do
          include Vigilante::WatchedOperator
        end
      end

    end

  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
vigilante-1.0.19 lib/vigilante/active_record_extensions.rb
vigilante-1.0.18 lib/vigilante/active_record_extensions.rb
vigilante-1.0.17 lib/vigilante/active_record_extensions.rb
vigilante-1.0.16 lib/vigilante/active_record_extensions.rb
vigilante-1.0.15 lib/vigilante/active_record_extensions.rb
vigilante-1.0.14 lib/vigilante/active_record_extensions.rb
vigilante-1.0.13 lib/vigilante/active_record_extensions.rb
vigilante-1.0.12 lib/vigilante/active_record_extensions.rb
vigilante-1.0.11 lib/vigilante/active_record_extensions.rb
vigilante-1.0.10 lib/vigilante/active_record_extensions.rb
vigilante-1.0.9 lib/vigilante/active_record_extensions.rb
vigilante-1.0.8 lib/vigilante/active_record_extensions.rb
vigilante-1.0.7 lib/vigilante/active_record_extensions.rb
vigilante-1.0.6 lib/vigilante/active_record_extensions.rb