Provide more context for unknown actions

This commit is contained in:
Joe Nelson
2015-11-18 23:51:38 -08:00
parent ffeb02e72e
commit b260cff6fd
+8 -7
View File
@@ -23,6 +23,7 @@ type RequestBody = BL.ByteString
data Action = ActionCreate | ActionRead data Action = ActionCreate | ActionRead
| ActionUpdate | ActionDelete | ActionUpdate | ActionDelete
| ActionInfo | ActionInvoke | ActionInfo | ActionInvoke
| ActionUnknown BS.ByteString
-- | The target db object of a user action -- | The target db object of a user action
data Target = TargetIdent QualifiedIdentifier data Target = TargetIdent QualifiedIdentifier
| TargetRoot | TargetRoot
@@ -42,7 +43,7 @@ data Payload = PayloadJSON JSON.Array
-- if it is an action we are able to perform. -- if it is an action we are able to perform.
data Intent = Intent { data Intent = Intent {
-- | Set to Nothing for unknown HTTP verbs -- | Set to Nothing for unknown HTTP verbs
iAction :: Maybe Action iAction :: Action
-- | Set to Nothing for malformed range -- | Set to Nothing for malformed range
, iRange :: Maybe NonnegRange , iRange :: Maybe NonnegRange
-- | Set to Nothing for strangely nested urls -- | Set to Nothing for strangely nested urls
@@ -63,14 +64,14 @@ data Intent = Intent {
userIntent :: Schema -> Request -> RequestBody -> Intent userIntent :: Schema -> Request -> RequestBody -> Intent
userIntent schema req reqBody = userIntent schema req reqBody =
let action = case requestMethod req of let action = case requestMethod req of
"GET" -> Just ActionRead "GET" -> ActionRead
"POST" -> Just $ if isTargetingProc "POST" -> if isTargetingProc
then ActionInvoke then ActionInvoke
else ActionCreate else ActionCreate
"PATCH" -> Just ActionUpdate "PATCH" -> ActionUpdate
"DELETE" -> Just ActionDelete "DELETE" -> ActionDelete
"OPTIONS" -> Just ActionInfo "OPTIONS" -> ActionInfo
_ -> Nothing other -> ActionUnknown other
target = case path of target = case path of
[] -> Just TargetRoot [] -> Just TargetRoot
[table] -> Just $ TargetIdent [table] -> Just $ TargetIdent