Sha256: 0ccf05d96447e33877b89820c16122c9e30169675ea480f8dacff6b64635319b

Contents?: true

Size: 839 Bytes

Versions: 51

Compression:

Stored size: 839 Bytes

Contents

module Fiona7
  class PermissionVolatileCache
    PERMISSION_KEY = "F7PERMISSION_CACHE"

    def initialize(request)
      request[PERMISSION_KEY] ||= {}
      self.storage = request[PERMISSION_KEY]
    end

    def permitted?(user_name, obj_id, action)
      self.storage["#{user_name}:#{obj_id}:#{action}"] ||= lookup(user_name, obj_id, action)
    end

    protected
    attr_accessor :storage

    def lookup(user_name, obj_id, action)
      return false unless user_name && obj_id && action

      obj = Fiona7::EditedObj.new
      obj.obj_id = obj_id.to_i
      return obj.permission.send(:"#{action}?", user_name)
    rescue Reactor::Cm::XmlSingleRequestError => e
      Rails.logger.error("Error looking up the permission of #{user_name} for obj #{obj_id} for action #{action}:\n#{e.message}")
      return false
    end
  end
end

Version data entries

51 entries across 51 versions & 1 rubygems

Version Path
infopark_fiona7-1.6.1.1.5 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.6.1.1.1 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.6.1.1.0 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.2.0.2.3 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.2.0.2.1 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.2.0.2.2 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.5.5.1 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.5.5.0 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.2.0.1.4 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.5.4.1 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.5.4.0 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.2.0.1.3 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.5.3.1 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.4.3.0 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.3.2.0 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.3.2.0.pre.beta1 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.2.1.0.pre.beta1 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.5.2.0.0 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.2.0.1.1 lib/fiona7/permission_volatile_cache.rb
infopark_fiona7-1.2.0.0.1 lib/fiona7/permission_volatile_cache.rb