Replace CDB_UserTables with new version

fix for #64
master
Paul Ramsey 9 years ago
parent b1e1723e75
commit ba521461fe

@ -6,34 +6,22 @@
-- Currently accepted permissions are: 'public', 'private' or 'all' -- Currently accepted permissions are: 'public', 'private' or 'all'
-- --
CREATE OR REPLACE FUNCTION CDB_UserTables(perm text DEFAULT 'all') CREATE OR REPLACE FUNCTION CDB_UserTables(perm text DEFAULT 'all')
RETURNS SETOF information_schema.sql_identifier RETURNS SETOF name
AS $$ AS $$
WITH usertables AS (
-- TODO: query CDB_TableMetadata for this ? SELECT c.relname
-- See http://github.com/CartoDB/cartodb/issues/254#issuecomment-26044777 FROM pg_class c
SELECT table_name as t JOIN pg_roles r ON r.oid = c.relowner
FROM information_schema.tables JOIN pg_namespace n ON n.oid = c.relnamespace
WHERE WHERE r.rolname = current_user
table_type='BASE TABLE' AND c.relkind = 'r'
AND table_schema='public' AND c.relname NOT IN ('cdb_tablemetadata', 'spatial_ref_sys')
AND table_name NOT IN ( AND n.nspname NOT IN ('pg_catalog', 'information_schema')
'cdb_tablemetadata', AND CASE WHEN perm = 'public' THEN has_table_privilege('public', c.oid, 'SELECT')
'spatial_ref_sys' WHEN perm = 'private' THEN has_table_privilege(c.oid, 'SELECT') AND NOT
) has_table_privilege('public', c.oid, 'SELECT')
), perms AS ( ELSE has_table_privilege(c.oid, 'SELECT') END;
SELECT t, has_table_privilege('public', 'public'||'.'||t, 'SELECT') as p
FROM usertables
)
SELECT t FROM perms
WHERE (
p = CASE WHEN $1 = 'private' THEN false
WHEN $1 = 'public' THEN true
ELSE not p -- none
END
OR $1 = 'all'
)
AND has_table_privilege('public'||'.'||t, 'SELECT')
;
$$ LANGUAGE 'sql'; $$ LANGUAGE 'sql';
-- This is to migrate from pre-0.2.0 version -- This is to migrate from pre-0.2.0 version

Loading…
Cancel
Save