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