def validate_filters(where, resource):
 operators = getattr(app.data, 'operators', set())
 allowed = (config.DOMAIN[resource]['allowed_filters'] + list(operators))
 def validate_filter(filter):
  for (key, value) in filter.items():
   if (('*' not in allowed) and (key not in allowed)):
    return ("filter on '%s' not allowed" % key)
   if (key in ('$or', '$and', '$nor')):
    if (not isinstance(value, list)):
     return ("operator '%s' expects a list of sub-queries" % key)
    for v in value:
     if (not isinstance(v, dict)):
      return ("operator '%s' expects a list of sub-queries" % key)
     r = validate_filter(v)
     if r:
      return r
   elif config.VALIDATE_FILTERS:
    res_schema = config.DOMAIN[resource]['schema']
    if (key not in res_schema):
     return "filter on '%s' is invalid"
    else:
     field_schema = res_schema.get(key)
     v = Validator({key: field_schema})
     if (not v.validate({key: value})):
      return "filter on '%s' is invalid"
     else:
      return None
 if (('*' in allowed) and (not config.VALIDATE_FILTERS)):
  return None
 return validate_filter(where)

def validate_filters ( where , resource ) : operators = getattr ( app . data , 'operators' , set ( ) ) allowed = ( config . DOMAIN [ resource ] [ 'allowed_filters' ] + list ( operators ) ) def validate_filter ( filter ) : for ( key , value ) in filter . items ( ) : if ( ( '*' not in allowed ) and ( key not in allowed ) ) : return ( "filter on '%s' not allowed" % key ) if ( key in ( '$or' , '$and' , '$nor' ) ) : if ( not isinstance ( value , list ) ) : return ( "operator '%s' expects a list of sub-queries" % key ) for v in value : if ( not isinstance ( v , dict ) ) : return ( "operator '%s' expects a list of sub-queries" % key ) r = validate_filter ( v ) if r : return r elif config . VALIDATE_FILTERS : res_schema = config . DOMAIN [ resource ] [ 'schema' ] if ( key not in res_schema ) : return "filter on '%s' is invalid" else : field_schema = res_schema . get ( key ) v = Validator ( { key : field_schema } ) if ( not v . validate ( { key : value } ) ) : return "filter on '%s' is invalid" else : return None if ( ( '*' in allowed ) and ( not config . VALIDATE_FILTERS ) ) : return None return validate_filter ( where )
validate that the filters are appropriate for the action type .