From f31848f2e5e02e193b205e83f2237b6979b2a1e2 Mon Sep 17 00:00:00 2001 From: Wolfgang Walther Date: Sat, 22 Jun 2024 19:43:41 +0200 Subject: [PATCH] refactor: Simplify funcsSqlQuery This allows to re-use ANY($$1) in the next commit. --- src/PostgREST/Query.hs | 2 +- src/PostgREST/SchemaCache.hs | 13 ++++++------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/src/PostgREST/Query.hs b/src/PostgREST/Query.hs index cf9833e16..17c585470 100644 --- a/src/PostgREST/Query.hs +++ b/src/PostgREST/Query.hs @@ -181,7 +181,7 @@ actionQuery (MaybeDb plan@InspectPlan{ipSchema=tSchema}) AppConfig{..} _ _ sCach tableAccess <- SQL.statement [tSchema] (SchemaCache.accessibleTables configDbPreparedStatements) MaybeDbResult plan . Just <$> ((,,) (HM.filterWithKey (\qi _ -> S.member qi tableAccess) $ SchemaCache.dbTables sCache) - <$> SQL.statement (tSchema, configDbHoistedTxSettings) (SchemaCache.accessibleFuncs configDbPreparedStatements) + <$> SQL.statement ([tSchema], configDbHoistedTxSettings) (SchemaCache.accessibleFuncs configDbPreparedStatements) <*> SQL.statement tSchema (SchemaCache.schemaDescription configDbPreparedStatements)) OAIgnorePriv -> MaybeDbResult plan . Just <$> ((,,) diff --git a/src/PostgREST/SchemaCache.hs b/src/PostgREST/SchemaCache.hs index 288ce22d5..bcf5a287a 100644 --- a/src/PostgREST/SchemaCache.hs +++ b/src/PostgREST/SchemaCache.hs @@ -360,21 +360,19 @@ dataRepresentations = SQL.Statement sql mempty decodeRepresentations |] allFunctions :: Bool -> SQL.Statement AppConfig RoutineMap -allFunctions = SQL.Statement sql params decodeFuncs +allFunctions = SQL.Statement funcsSqlQuery params decodeFuncs where params = (toList . configDbSchemas >$< arrayParam HE.text) <> (configDbHoistedTxSettings >$< arrayParam HE.text) - sql = - funcsSqlQuery <> " AND pn.nspname = ANY($1)" -accessibleFuncs :: Bool -> SQL.Statement (Schema, [Text]) RoutineMap +accessibleFuncs :: Bool -> SQL.Statement ([Schema], [Text]) RoutineMap accessibleFuncs = SQL.Statement sql params decodeFuncs where params = - (fst >$< param HE.text) <> + (fst >$< arrayParam HE.text) <> (snd >$< arrayParam HE.text) - sql = funcsSqlQuery <> " AND pn.nspname = $1 AND has_function_privilege(p.oid, 'execute')" + sql = funcsSqlQuery <> " AND has_function_privilege(p.oid, 'execute')" funcsSqlQuery :: SqlQuery funcsSqlQuery = encodeUtf8 [trimming| @@ -465,7 +463,8 @@ funcsSqlQuery = encodeUtf8 [trimming| WHERE setting ~ ANY($$2) ) func_settings ON TRUE WHERE t.oid <> 'trigger'::regtype AND COALESCE(a.callable, true) - AND prokind = 'f'|] + AND prokind = 'f' + AND pn.nspname = ANY($$1) |] schemaDescription :: Bool -> SQL.Statement Schema (Maybe Text) schemaDescription =