This commit is contained in:
2020-02-14 20:53:33 +00:00
parent 49f98efa50
commit 8c0bdb05de

View File

@@ -232,21 +232,23 @@ namespace AyaNova.Biz
AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "ListKey", "255 max"); AddError(ApiErrorCode.VALIDATION_LENGTH_EXCEEDED, "ListKey", "255 max");
//Filter json must parse //Filter json must parse
//this is all automated normally so not going to do too much parsing here
//just ensure it's basically there
if (!string.IsNullOrWhiteSpace(inObj.ListView)) if (!string.IsNullOrWhiteSpace(inObj.ListView))
{ {
try try
{ {
var v = JArray.Parse(inObj.Filter); var v = JArray.Parse(inObj.ListView);
for (int i = 0; i < v.Count; i++) for (int i = 0; i < v.Count; i++)
{ {
var filterItem = v[i]; var filterItem = v[i];
if (filterItem["fld"] == null) if (filterItem["fld"] == null)
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing required \"fld\" property "); AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListView", $"ListView array item {i}, object is missing required \"fld\" property ");
else else
{ {
var fld = filterItem["fld"].Value<string>(); var fld = filterItem["fld"].Value<string>();
if (string.IsNullOrWhiteSpace(fld)) if (string.IsNullOrWhiteSpace(fld))
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, \"fld\" property is empty and required"); AddError(ApiErrorCode.VALIDATION_REQUIRED, "ListView", $"ListView array item {i}, \"fld\" property is empty and required");
//validate the field name if we can //validate the field name if we can
if (DataList != null) if (DataList != null)
@@ -256,38 +258,33 @@ namespace AyaNova.Biz
if (TheField == null) if (TheField == null)
{ {
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", $"Filter array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified"); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", $"ListView array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified");
} }
else if (TheField.IsFilterable == false)
{
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", $"Filter array item {i}, fld property value \"{fld}\" is not filterable");
}
} }
} }
if (filterItem["op"] == null) //This is the old filter validation code but at this point only going to validate that the fields are present and valid as the bare minimum
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing required \"op\" property "); // if (filterItem["op"] == null)
else // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing required \"op\" property ");
{ // else
var opType = filterItem["op"].Value<string>(); // {
if (!DataListFilterComparisonOperator.Operators.Contains(opType)) // var opType = filterItem["op"].Value<string>();
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", $"Filter array item {i}, \"op\" property value of \"{opType}\" is not a valid FilterComparisonOperator type"); // if (!DataListFilterComparisonOperator.Operators.Contains(opType))
} // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", $"Filter array item {i}, \"op\" property value of \"{opType}\" is not a valid FilterComparisonOperator type");
// }
if (filterItem["value"] == null) // if (filterItem["value"] == null)
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property "); // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ");
else // else
{ // {
//check if the value is present, not what it is exactly, just that it's present // //check if the value is present, not what it is exactly, just that it's present
//value also could contain relative date tokens, not that it checks them anyway but just noting it here // //value also could contain relative date tokens, not that it checks them anyway but just noting it here
if (filterItem["value"].Type == JTokenType.String && string.IsNullOrWhiteSpace(filterItem["value"].Value<string>())) // if (filterItem["value"].Type == JTokenType.String && string.IsNullOrWhiteSpace(filterItem["value"].Value<string>()))
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property "); // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ");
if (filterItem["value"].Type == JTokenType.Array && filterItem["value"].Count() == 0) // if (filterItem["value"].Type == JTokenType.Array && filterItem["value"].Count() == 0)
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ARRAY "); // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Filter", $"Filter array item {i}, object is missing or is empty the required \"value\" property ARRAY ");
} // }
//NOTE: value of nothing, null or empty is a valid value so no checking for it here //NOTE: value of nothing, null or empty is a valid value so no checking for it here
@@ -295,58 +292,58 @@ namespace AyaNova.Biz
} }
catch (Newtonsoft.Json.JsonReaderException ex) catch (Newtonsoft.Json.JsonReaderException ex)
{ {
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Filter", "Filter is not valid JSON string: " + ex.Message); AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "ListView", "ListView is not valid JSON string: " + ex.Message);
} }
} }
//VALIDATE SORT // //VALIDATE SORT
//Filter json must parse // //Filter json must parse
if (!string.IsNullOrWhiteSpace(inObj.Sort)) // if (!string.IsNullOrWhiteSpace(inObj.Sort))
{ // {
try // try
{ // {
var v = JArray.Parse(inObj.Sort); // var v = JArray.Parse(inObj.Sort);
for (int i = 0; i < v.Count; i++) // for (int i = 0; i < v.Count; i++)
{ // {
var sortItem = v[i]; // var sortItem = v[i];
if (sortItem["fld"] == null) // if (sortItem["fld"] == null)
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, object is missing required \"fld\" property "); // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, object is missing required \"fld\" property ");
else // else
{ // {
var fld = sortItem["fld"].Value<string>(); // var fld = sortItem["fld"].Value<string>();
if (string.IsNullOrWhiteSpace(fld)) // if (string.IsNullOrWhiteSpace(fld))
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, \"fld\" property is empty and required"); // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, \"fld\" property is empty and required");
//validate the field name if we can // //validate the field name if we can
if (DataList != null) // if (DataList != null)
{ // {
if (!DataList.FieldDefinitions.Exists(x => x.FieldKey.ToLowerInvariant() == fld && x.IsFilterable)) // if (!DataList.FieldDefinitions.Exists(x => x.FieldKey.ToLowerInvariant() == fld && x.IsFilterable))
{ // {
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified"); // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, fld property value \"{fld}\" is not a valid value for ListKey specified");
} // }
} // }
} // }
if (sortItem["dir"] == null) // if (sortItem["dir"] == null)
AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, object is missing required \"dir\" sort direction property "); // AddError(ApiErrorCode.VALIDATION_REQUIRED, "Sort", $"Sort array item {i}, object is missing required \"dir\" sort direction property ");
else // else
{ // {
var sortDir = sortItem["dir"].Value<string>(); // var sortDir = sortItem["dir"].Value<string>();
if (sortDir != "+" && sortDir != "-") // if (sortDir != "+" && sortDir != "-")
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, \"dir\" property value of \"{sortDir}\" is not a valid sort direction value, must be \"+\" or \"-\" only"); // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", $"Sort array item {i}, \"dir\" property value of \"{sortDir}\" is not a valid sort direction value, must be \"+\" or \"-\" only");
} // }
//NOTE: value of nothing, null or empty is a valid value so no checking for it here // //NOTE: value of nothing, null or empty is a valid value so no checking for it here
} // }
} // }
catch (Newtonsoft.Json.JsonReaderException ex) // catch (Newtonsoft.Json.JsonReaderException ex)
{ // {
AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", "Sort is not valid JSON string: " + ex.Message); // AddError(ApiErrorCode.VALIDATION_INVALID_VALUE, "Sort", "Sort is not valid JSON string: " + ex.Message);
} // }
} // }