From 594327924c696dce7306926bbff99e7426b003b9 Mon Sep 17 00:00:00 2001 From: Joe Nelson Date: Tue, 25 Aug 2015 23:33:44 -0700 Subject: [PATCH] Set role locally in a tx to ensure it is reset after error --- src/PostgREST/Auth.hs | 4 ++-- src/PostgREST/Main.hs | 2 +- test/SpecHelper.hs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/PostgREST/Auth.hs b/src/PostgREST/Auth.hs index 597dae421..6f42eafbb 100644 --- a/src/PostgREST/Auth.hs +++ b/src/PostgREST/Auth.hs @@ -53,14 +53,14 @@ checkPass :: Text -> Text -> Bool checkPass = (. cs) . validatePassword . cs setRole :: Text -> H.Tx P.Postgres s () -setRole role = H.unitEx $ B.Stmt ("set role " <> cs (pgFmtLit role)) V.empty True +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 user_vars.user_id = " <> cs (pgFmtLit uid)) V.empty True + H.unitEx $ B.Stmt ("set local user_vars.user_id = " <> cs (pgFmtLit uid)) V.empty True else resetUserId diff --git a/src/PostgREST/Main.hs b/src/PostgREST/Main.hs index acae88bd6..e7a9d40ef 100644 --- a/src/PostgREST/Main.hs +++ b/src/PostgREST/Main.hs @@ -73,7 +73,7 @@ main = do runSettings appSettings $ middle $ \req respond -> do body <- strictRequestBody req - resOrError <- liftIO $ H.session pool $ H.tx Nothing $ + resOrError <- liftIO $ H.session pool $ H.tx (Just (H.ReadUncommitted, Just True)) $ authenticated conf (app conf body) req either (respond . errResponse) respond resOrError diff --git a/test/SpecHelper.hs b/test/SpecHelper.hs index a9c5df075..e24c75fb1 100644 --- a/test/SpecHelper.hs +++ b/test/SpecHelper.hs @@ -54,7 +54,7 @@ withApp perform = do perform $ middle $ \req resp -> do body <- strictRequestBody req - result <- liftIO $ H.session pool $ H.tx Nothing + result <- liftIO $ H.session pool $ H.tx (Just (H.ReadUncommitted, Just True)) $ authenticated cfg (app cfg body) req either (resp . errResponse) resp result