Fix options on non existant tables, closes #442
This commit is contained in:
@@ -7,6 +7,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
|||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Reject non-POSTs to rpc endpoints - @begriffs
|
- Reject non-POSTs to rpc endpoints - @begriffs
|
||||||
|
- Throw an error for OPTIONS on nonexistent tables - @calebmer
|
||||||
|
|
||||||
## [0.3.0.3] - 2016-01-08
|
## [0.3.0.3] - 2016-01-08
|
||||||
|
|
||||||
|
|||||||
+12
-9
@@ -11,7 +11,7 @@ import Control.Arrow ((***))
|
|||||||
import Control.Monad (join)
|
import Control.Monad (join)
|
||||||
import Data.Bifunctor (first)
|
import Data.Bifunctor (first)
|
||||||
import Data.List (find, sortBy, delete)
|
import Data.List (find, sortBy, delete)
|
||||||
import Data.Maybe (fromMaybe, fromJust, mapMaybe)
|
import Data.Maybe (isJust, fromMaybe, fromJust, mapMaybe)
|
||||||
import Data.Ord (comparing)
|
import Data.Ord (comparing)
|
||||||
import Data.Ranged.Ranges (emptyRange)
|
import Data.Ranged.Ranges (emptyRange)
|
||||||
import Data.String.Conversions (cs)
|
import Data.String.Conversions (cs)
|
||||||
@@ -146,14 +146,17 @@ app dbStructure conf reqBody req =
|
|||||||
then notFound
|
then notFound
|
||||||
else responseLBS status204 [("Content-Range", "*/"<> cs (show queryTotal))] ""
|
else responseLBS status204 [("Content-Range", "*/"<> cs (show queryTotal))] ""
|
||||||
|
|
||||||
(ActionInfo, TargetIdent (QualifiedIdentifier tSchema tTable), Nothing) -> do
|
(ActionInfo, TargetIdent (QualifiedIdentifier tSchema tTable), Nothing) ->
|
||||||
let cols = filter (filterCol tSchema tTable) $ dbColumns dbStructure
|
if isJust $ find (\t -> tableName t == tTable && tableSchema t == tSchema) (dbTables dbStructure)
|
||||||
pkeys = map pkName $ filter (filterPk tSchema tTable) allPrKeys
|
then let cols = filter (filterCol tSchema tTable) $ dbColumns dbStructure
|
||||||
body = encode (TableOptions cols pkeys)
|
pkeys = map pkName $ filter (filterPk tSchema tTable) allPrKeys
|
||||||
filterCol :: Schema -> TableName -> Column -> Bool
|
body = encode (TableOptions cols pkeys)
|
||||||
filterCol sc tb Column{colTable=Table{tableSchema=s, tableName=t}} = s==sc && t==tb
|
filterCol :: Schema -> TableName -> Column -> Bool
|
||||||
filterCol _ _ _ = False
|
filterCol sc tb (Column{colTable=Table{tableSchema=s, tableName=t}}) = s==sc && t==tb
|
||||||
return $ responseLBS status200 [jsonH, allOrigins] $ cs body
|
filterCol _ _ _ = False in
|
||||||
|
return $ responseLBS status200 [jsonH, allOrigins] $ cs body
|
||||||
|
else
|
||||||
|
return notFound
|
||||||
|
|
||||||
(ActionInvoke, TargetProc qi,
|
(ActionInvoke, TargetProc qi,
|
||||||
Just (PayloadJSON (UniformObjects payload))) -> do
|
Just (PayloadJSON (UniformObjects payload))) -> do
|
||||||
|
|||||||
@@ -320,3 +320,6 @@ spec struct c = around (withApp cfgDefault struct c) $ do
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
|]
|
|]
|
||||||
|
|
||||||
|
it "errors for non existant tables" $
|
||||||
|
request methodOptions "/dne" [] "" `shouldRespondWith` 404
|
||||||
|
|||||||
Reference in New Issue
Block a user