Check `[NotFilterable]` for collection properties in v4 `FilterQueryValidator`

nits:
- add another missing `default` case in a validation `switch` statement
- clean up "no default validation logic here" comments
This commit is contained in:
dougbu 2014-09-23 07:08:11 -07:00
Родитель 5a630cbb87
Коммит 152c6b18a3
6 изменённых файлов: 47 добавлений и 14 удалений

Просмотреть файл

@ -257,7 +257,7 @@ namespace System.Web.Http.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// No default validation logic here.
}
/// <summary>
@ -281,7 +281,7 @@ namespace System.Web.Http.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// Validate child nodes but not the ConvertNode itself.
ValidateQueryNode(convertNode.Source, settings);
}
@ -302,7 +302,7 @@ namespace System.Web.Http.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// No default validation logic here.
// recursion
if (sourceNode != null)
@ -332,7 +332,7 @@ namespace System.Web.Http.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// No default validation logic here.
}
/// <summary>
@ -356,7 +356,7 @@ namespace System.Web.Http.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// No default validation logic here.
ValidateQueryNode(propertyAccessNode.Source, settings);
}
@ -381,7 +381,7 @@ namespace System.Web.Http.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// No default validation logic here.
ValidateQueryNode(propertyAccessNode.Source, settings);
}
@ -436,6 +436,9 @@ namespace System.Web.Http.OData.Query.Validators
throw new ODataException(Error.Format(SRResources.NotAllowedLogicalOperator, unaryOperatorNode.OperatorKind, "AllowedLogicalOperators"));
}
break;
default:
throw Error.NotSupported(SRResources.UnaryNodeValidationNotSupported, unaryOperatorNode.OperatorKind, typeof(FilterQueryValidator).Name);
}
}

Просмотреть файл

@ -1635,6 +1635,15 @@ namespace System.Web.Http.OData.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Validating OData UnaryOperatorNode of kind {0} is not supported by {1}..
/// </summary>
internal static string UnaryNodeValidationNotSupported {
get {
return ResourceManager.GetString("UnaryNodeValidationNotSupported", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The element type &apos;{0}&apos; of the given collection type &apos;{1}&apos; is not of the type &apos;{2}&apos;..
/// </summary>

Просмотреть файл

@ -204,6 +204,9 @@
<data name="QueryNodeValidationNotSupported" xml:space="preserve">
<value>Validating OData QueryNode of kind {0} is not supported by {1}.</value>
</data>
<data name="UnaryNodeValidationNotSupported" xml:space="preserve">
<value>Validating OData UnaryOperatorNode of kind {0} is not supported by {1}.</value>
</data>
<data name="OrderByDuplicateProperty" xml:space="preserve">
<value>Duplicate property named '{0}' is not supported in '$orderby'.</value>
</data>

Просмотреть файл

@ -263,7 +263,7 @@ namespace System.Web.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// No default validation logic here.
}
/// <summary>
@ -287,7 +287,7 @@ namespace System.Web.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// Validate child nodes but not the ConvertNode itself.
ValidateQueryNode(convertNode.Source, settings);
}
@ -314,8 +314,6 @@ namespace System.Web.OData.Query.Validators
throw new ODataException(Error.Format(SRResources.NotFilterablePropertyUsedInFilter, navigationProperty.Name));
}
// no default validation logic here
// recursion
if (sourceNode != null)
{
@ -344,7 +342,7 @@ namespace System.Web.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// No default validation logic here.
}
/// <summary>
@ -368,14 +366,13 @@ namespace System.Web.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// Check whether the property is not filterable
// Check whether the property is filterable.
IEdmProperty property = propertyAccessNode.Property;
if (EdmLibHelpers.IsNotFilterable(property, _model))
{
throw new ODataException(Error.Format(SRResources.NotFilterablePropertyUsedInFilter, property.Name));
}
// no default validation logic here
ValidateQueryNode(propertyAccessNode.Source, settings);
}
@ -400,7 +397,13 @@ namespace System.Web.OData.Query.Validators
throw Error.ArgumentNull("settings");
}
// no default validation logic here
// Check whether the property is filterable.
IEdmProperty property = propertyAccessNode.Property;
if (EdmLibHelpers.IsNotFilterable(property, _model))
{
throw new ODataException(Error.Format(SRResources.NotFilterablePropertyUsedInFilter, property.Name));
}
ValidateQueryNode(propertyAccessNode.Source, settings);
}
@ -484,6 +487,9 @@ namespace System.Web.OData.Query.Validators
throw new ODataException(Error.Format(SRResources.NotAllowedLogicalOperator, unaryOperatorNode.OperatorKind, "AllowedLogicalOperators"));
}
break;
default:
throw Error.NotSupported(SRResources.UnaryNodeValidationNotSupported, unaryOperatorNode.OperatorKind, typeof(FilterQueryValidator).Name);
}
}

Просмотреть файл

@ -1878,6 +1878,15 @@ namespace System.Web.OData.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Validating OData UnaryOperatorNode of kind {0} is not supported by {1}..
/// </summary>
internal static string UnaryNodeValidationNotSupported {
get {
return ResourceManager.GetString("UnaryNodeValidationNotSupported", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to The element type &apos;{0}&apos; of the given collection type &apos;{1}&apos; is not of the type &apos;{2}&apos;..
/// </summary>

Просмотреть файл

@ -201,6 +201,9 @@
<data name="QueryNodeValidationNotSupported" xml:space="preserve">
<value>Validating OData QueryNode of kind {0} is not supported by {1}.</value>
</data>
<data name="UnaryNodeValidationNotSupported" xml:space="preserve">
<value>Validating OData UnaryOperatorNode of kind {0} is not supported by {1}.</value>
</data>
<data name="OrderByDuplicateProperty" xml:space="preserve">
<value>Duplicate property named '{0}' is not supported in '$orderby'.</value>
</data>