fix: prevent spread embed to use aggregates when disabled
This commit is contained in:
@@ -13,6 +13,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
- #2858, Performance improvements when calling RPCs via GET using indexes in more cases - @wolfgangwalther
|
- #2858, Performance improvements when calling RPCs via GET using indexes in more cases - @wolfgangwalther
|
||||||
- #3560, Log resolved host in "Listening on ..." messages - @develop7
|
- #3560, Log resolved host in "Listening on ..." messages - @develop7
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- #3693, Prevent spread embedding to allow aggregates when they are disabled - @laurenceisla
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
- #2052, Dropped support for PostgreSQL 9.6 - @wolfgangwalther
|
- #2052, Dropped support for PostgreSQL 9.6 - @wolfgangwalther
|
||||||
|
|||||||
@@ -332,8 +332,8 @@ readPlan qi@QualifiedIdentifier{..} AppConfig{configDbMaxRows, configDbAggregate
|
|||||||
in
|
in
|
||||||
mapLeft ApiRequestError $
|
mapLeft ApiRequestError $
|
||||||
treeRestrictRange configDbMaxRows (iAction apiRequest) =<<
|
treeRestrictRange configDbMaxRows (iAction apiRequest) =<<
|
||||||
validateAggFunctions configDbAggregates =<<
|
|
||||||
hoistSpreadAggFunctions =<<
|
hoistSpreadAggFunctions =<<
|
||||||
|
validateAggFunctions configDbAggregates =<<
|
||||||
addRelSelects =<<
|
addRelSelects =<<
|
||||||
addNullEmbedFilters =<<
|
addNullEmbedFilters =<<
|
||||||
validateSpreadEmbeds =<<
|
validateSpreadEmbeds =<<
|
||||||
@@ -721,8 +721,7 @@ hoistIntoRelSelectFields _ r = r
|
|||||||
|
|
||||||
validateAggFunctions :: Bool -> ReadPlanTree -> Either ApiRequestError ReadPlanTree
|
validateAggFunctions :: Bool -> ReadPlanTree -> Either ApiRequestError ReadPlanTree
|
||||||
validateAggFunctions aggFunctionsAllowed (Node rp@ReadPlan {select} forest)
|
validateAggFunctions aggFunctionsAllowed (Node rp@ReadPlan {select} forest)
|
||||||
| aggFunctionsAllowed = Node rp <$> traverse (validateAggFunctions aggFunctionsAllowed) forest
|
| not aggFunctionsAllowed && any (isJust . csAggFunction) select = Left AggregatesNotAllowed
|
||||||
| any (isJust . csAggFunction) select = Left AggregatesNotAllowed
|
|
||||||
| otherwise = Node rp <$> traverse (validateAggFunctions aggFunctionsAllowed) forest
|
| otherwise = Node rp <$> traverse (validateAggFunctions aggFunctionsAllowed) forest
|
||||||
|
|
||||||
addFilters :: ResolverContext -> ApiRequest -> ReadPlanTree -> Either ApiRequestError ReadPlanTree
|
addFilters :: ResolverContext -> ApiRequest -> ReadPlanTree -> Either ApiRequestError ReadPlanTree
|
||||||
|
|||||||
@@ -166,3 +166,25 @@ disallowed =
|
|||||||
}|]
|
}|]
|
||||||
{ matchStatus = 400
|
{ matchStatus = 400
|
||||||
, matchHeaders = [matchContentTypeJson] }
|
, matchHeaders = [matchContentTypeJson] }
|
||||||
|
|
||||||
|
it "prevents the use of aggregates on embedded relationships" $
|
||||||
|
get "/projects?select=name,project_invoices(invoice_total.sum())" `shouldRespondWith`
|
||||||
|
[json|{
|
||||||
|
"hint":null,
|
||||||
|
"details":null,
|
||||||
|
"code":"PGRST123",
|
||||||
|
"message":"Use of aggregate functions is not allowed"
|
||||||
|
}|]
|
||||||
|
{ matchStatus = 400
|
||||||
|
, matchHeaders = [matchContentTypeJson] }
|
||||||
|
|
||||||
|
it "prevents the use of aggregates on spread embeds" $
|
||||||
|
get "/project_invoices?select=...projects(id.count())" `shouldRespondWith`
|
||||||
|
[json|{
|
||||||
|
"hint":null,
|
||||||
|
"details":null,
|
||||||
|
"code":"PGRST123",
|
||||||
|
"message":"Use of aggregate functions is not allowed"
|
||||||
|
}|]
|
||||||
|
{ matchStatus = 400
|
||||||
|
, matchHeaders = [matchContentTypeJson] }
|
||||||
|
|||||||
Reference in New Issue
Block a user