def flatten_privileges (privileges, context = nil, flattened_privileges = Set.new)
      # TODO caching?
      raise AuthorizationUsageError, "No context given or inferable from object" unless context
      privileges.reject {|priv| flattened_privileges.include?(priv)}.each do |priv|
        flattened_privileges << priv
        flatten_privileges(rev_priv_hierarchy[[priv, nil]], context, flattened_privileges) if rev_priv_hierarchy[[priv, nil]]
        flatten_privileges(rev_priv_hierarchy[[priv, context]], context, flattened_privileges) if rev_priv_hierarchy[[priv, context]]
      end
      flattened_privileges.to_a
    end
def flatten_privileges (privileges, context = nil, flattened_privileges = Set.new)
      # TODO caching?
      raise AuthorizationUsageError, "No context given or inferable from object" unless context
      privileges.reject {|priv| flattened_privileges.include?(priv)}.each do |priv|
        flattened_privileges << priv
        flatten_privileges(rev_priv_hierarchy[[priv, nil]], context, flattened_privileges) if rev_priv_hierarchy[[priv, nil]]
        flatten_privileges(rev_priv_hierarchy[[priv, context]], context, flattened_privileges) if rev_priv_hierarchy[[priv, context]]
      end
      flattened_privileges.to_a
    end
Returns the privilege hierarchy flattened for given privileges in context.