Let the transaction reset the role and user id for us

This commit is contained in:
Joe Nelson
2015-08-26 20:49:23 -07:00
parent 594327924c
commit 1656fb9f57
4 changed files with 8 additions and 14 deletions
-3
View File
@@ -55,9 +55,6 @@ checkPass = (. cs) . validatePassword . cs
setRole :: Text -> H.Tx P.Postgres s ()
setRole role = H.unitEx $ B.Stmt ("set local role " <> cs (pgFmtLit role)) V.empty True
resetRole :: H.Tx P.Postgres s ()
resetRole = H.unitEx [H.stmt|reset role|]
setUserId :: Text -> H.Tx P.Postgres s ()
setUserId uid = if uid /= "" then
H.unitEx $ B.Stmt ("set local user_vars.user_id = " <> cs (pgFmtLit uid)) V.empty True
+1 -1
View File
@@ -73,7 +73,7 @@ main = do
runSettings appSettings $ middle $ \req respond -> do
body <- strictRequestBody req
resOrError <- liftIO $ H.session pool $ H.tx (Just (H.ReadUncommitted, Just True)) $
resOrError <- liftIO $ H.session pool $ H.tx (Just (H.ReadCommitted, Just True)) $
authenticated conf (app conf body) req
either (respond . errResponse) respond resOrError
+2 -5
View File
@@ -23,7 +23,7 @@ import Network.Wai.Middleware.Static (staticPolicy, only)
import Network.URI (URI(..), parseURI)
import PostgREST.Config (AppConfig(..), corsPolicy)
import PostgREST.Auth (LoginAttempt(..), signInRole, signInWithJWT, setRole, resetRole, setUserId, resetUserId)
import PostgREST.Auth (LoginAttempt(..), signInRole, signInWithJWT, setRole, setUserId)
import PostgREST.App (contentTypeForAccept)
import Codec.Binary.Base64.String (decode)
@@ -62,10 +62,7 @@ authenticated conf app req = do
runInRole r uid = do
setUserId uid
setRole r
res <- app req
resetRole
resetUserId
return res
app req
redirectInsecure :: Application -> Application
+1 -1
View File
@@ -54,7 +54,7 @@ withApp perform = do
perform $ middle $ \req resp -> do
body <- strictRequestBody req
result <- liftIO $ H.session pool $ H.tx (Just (H.ReadUncommitted, Just True))
result <- liftIO $ H.session pool $ H.tx (Just (H.ReadCommitted, Just True))
$ authenticated cfg (app cfg body) req
either (resp . errResponse) resp result