diff --git a/web/pgadmin/tools/grant_wizard/__init__.py b/web/pgadmin/tools/grant_wizard/__init__.py index e3fc80f..7c09850 100644 --- a/web/pgadmin/tools/grant_wizard/__init__.py +++ b/web/pgadmin/tools/grant_wizard/__init__.py @@ -187,7 +187,6 @@ def properties(gid, sid, did, node_id, node_type): conn = manager.connection(did=did) node_types = [] - nspname = '' show_sysobj = blueprint.show_system_objects().get() if node_type == 'database': @@ -212,18 +211,16 @@ def properties(gid, sid, did, node_id, node_type): return internal_server_error(errormsg=res) node_types = res['rows'] ntype = node_type - nspname = node_types[0]['name'] for row in node_types: if 'oid' in row: node_id = row['oid'] - nspname = row['name'] # Fetch functions against schema if ntype in ['schema', 'function']: SQL = render_template("/".join( [server_prop['template_path'], '/sql/function.sql']), - node_id=node_id, nspname=nspname, type='function') + node_id=node_id, type='function') status, res = conn.execute_dict(SQL) @@ -238,7 +235,7 @@ def properties(gid, sid, did, node_id, node_type): ntype in ['schema', 'procedure']): SQL = render_template("/".join( [server_prop['template_path'], '/sql/function.sql']), - node_id=node_id, nspname=nspname, type='procedure') + node_id=node_id, type='procedure') status, res = conn.execute_dict(SQL) @@ -251,7 +248,7 @@ def properties(gid, sid, did, node_id, node_type): if ntype in ['schema', 'trigger_function']: SQL = render_template("/".join( [server_prop['template_path'], '/sql/function.sql']), - node_id=node_id, nspname=nspname, type='trigger_function') + node_id=node_id, type='trigger_function') status, res = conn.execute_dict(SQL) if not status: @@ -263,7 +260,7 @@ def properties(gid, sid, did, node_id, node_type): if ntype in ['schema', 'sequence']: SQL = render_template("/".join( [server_prop['template_path'], '/sql/sequence.sql']), - node_id=node_id, nspname=nspname) + node_id=node_id) status, res = conn.execute_dict(SQL) if not status: @@ -274,7 +271,7 @@ def properties(gid, sid, did, node_id, node_type): if ntype in ['schema', 'table']: SQL = render_template("/".join( [server_prop['template_path'], '/sql/table.sql']), - node_id=node_id, nspname=nspname) + node_id=node_id) status, res = conn.execute_dict(SQL) if not status: @@ -286,7 +283,7 @@ def properties(gid, sid, did, node_id, node_type): if ntype in ['schema', 'view']: SQL = render_template("/".join( [server_prop['template_path'], '/sql/view.sql']), - node_id=node_id, node_type='v', nspname=nspname) + node_id=node_id, node_type='v') status, res = conn.execute_dict(SQL) if not status: @@ -298,7 +295,7 @@ def properties(gid, sid, did, node_id, node_type): if ntype in ['schema', 'mview']: SQL = render_template("/".join( [server_prop['template_path'], '/sql/view.sql']), - node_id=node_id, node_type='m', nspname=nspname) + node_id=node_id, node_type='m') status, res = conn.execute_dict(SQL) if not status: diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/function.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/function.sql index 067606f..5f27ea6 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/function.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/function.sql @@ -1,16 +1,17 @@ {# ===== Fetch list of Database object types(Functions) ====== #} -{% if type and node_id and nspname %} +{% if type and node_id %} {% set func_type = 'Trigger Function' if type == 'trigger_function' else 'Function' %} {% set icon = 'icon-function' if type == 'function' else 'icon-trigger_function' %} SELECT pr.oid, pg_get_function_identity_arguments(pr.oid) AS proargs, pr.proname AS name, + nsp.nspname AS nspname, '{{ func_type }}' AS object_type, - '{{ nspname }}' AS nspname, '{{ icon }}' AS icon FROM pg_proc pr +JOIN pg_namespace nsp ON nsp.oid=pr.pronamespace JOIN pg_type typ ON typ.oid=prorettype JOIN pg_namespace typns ON typns.oid=typ.typnamespace JOIN pg_language lng ON lng.oid=prolang diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/sequence.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/sequence.sql index 2950df1..c49874b 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/sequence.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/sequence.sql @@ -1,12 +1,13 @@ {# ===== Fetch list of Database object types(Sequence) ===== #} -{% if node_id, nspname %} +{% if node_id %} SELECT cl.relname AS name, + nsp.nspname AS nspname, 'Sequence' AS object_type, - 'icon-sequence' AS icon, - '{{ nspname }}' AS nspname + 'icon-sequence' AS icon FROM pg_class cl +JOIN pg_namespace nsp ON nsp.oid=cl.relnamespace LEFT OUTER JOIN pg_description des ON (des.objoid=cl.oid AND des.classoid='pg_class'::regclass) WHERE relkind = 'S' AND relnamespace = {{ node_id }}::oid diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/table.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/table.sql index 5f67c49..3bfcf0b 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/table.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/table.sql @@ -1,12 +1,13 @@ {# ===== Fetch list of Database object types(Tables) ===== #} -{% if node_id and nspname %} +{% if node_id %} SELECT rel.relname AS name, + nsp.nspname AS nspname, 'Table' AS object_type, - 'icon-table' AS icon, - '{{ nspname }}' AS nspname + 'icon-table' AS icon FROM pg_class rel +JOIN pg_namespace nsp ON nsp.oid=rel.relnamespace LEFT OUTER JOIN pg_tablespace spc ON spc.oid=rel.reltablespace LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_constraint con ON con.conrelid=rel.oid AND con.contype='p' diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/view.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/view.sql index b16e7a3..a7aabb7 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/view.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/view.sql @@ -3,11 +3,12 @@ {% set ntype = "View" if node_type == 'v' else "Materialized View" %} SELECT c.relname AS name, + nsp.nspname AS nspname, '{{ ntype }}' AS object_type, - 'icon-view' AS icon, - '{{ nspname }}' AS nspname + 'icon-view' AS icon FROM pg_class c +JOIN pg_namespace nsp ON nsp.oid=c.relnamespace LEFT OUTER JOIN pg_tablespace spc ON spc.oid=c.reltablespace LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid and des.objsubid=0 AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_class tst ON tst.oid = c.reltoastrelid diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/function.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/function.sql index 855a841..822134d 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/function.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/function.sql @@ -1,16 +1,17 @@ {# ===== Fetch list of Database object types(Functions) ====== #} -{% if type and node_id and nspname %} +{% if type and node_id %} {% set func_type = 'Trigger Function' if type == 'trigger_function' else 'Procedure' if type == 'procedure' else 'Function' %} {% set icon = 'icon-function' if type == 'function' else 'icon-procedure' if type == 'procedure' else 'icon-trigger_function' %} SELECT pr.oid, pg_get_function_identity_arguments(pr.oid) AS proargs, pr.proname AS name, + nsp.nspname AS nspname, '{{ func_type }}' AS object_type, - '{{ nspname }}' AS nspname, '{{ icon }}' AS icon FROM pg_proc pr +JOIN pg_namespace nsp ON nsp.oid=pr.pronamespace JOIN pg_type typ ON typ.oid=prorettype JOIN pg_namespace typns ON typns.oid=typ.typnamespace JOIN pg_language lng ON lng.oid=prolang diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/sequence.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/sequence.sql index 2950df1..c49874b 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/sequence.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/sequence.sql @@ -1,12 +1,13 @@ {# ===== Fetch list of Database object types(Sequence) ===== #} -{% if node_id, nspname %} +{% if node_id %} SELECT cl.relname AS name, + nsp.nspname AS nspname, 'Sequence' AS object_type, - 'icon-sequence' AS icon, - '{{ nspname }}' AS nspname + 'icon-sequence' AS icon FROM pg_class cl +JOIN pg_namespace nsp ON nsp.oid=cl.relnamespace LEFT OUTER JOIN pg_description des ON (des.objoid=cl.oid AND des.classoid='pg_class'::regclass) WHERE relkind = 'S' AND relnamespace = {{ node_id }}::oid diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/table.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/table.sql index 5f67c49..3bfcf0b 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/table.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/table.sql @@ -1,12 +1,13 @@ {# ===== Fetch list of Database object types(Tables) ===== #} -{% if node_id and nspname %} +{% if node_id %} SELECT rel.relname AS name, + nsp.nspname AS nspname, 'Table' AS object_type, - 'icon-table' AS icon, - '{{ nspname }}' AS nspname + 'icon-table' AS icon FROM pg_class rel +JOIN pg_namespace nsp ON nsp.oid=rel.relnamespace LEFT OUTER JOIN pg_tablespace spc ON spc.oid=rel.reltablespace LEFT OUTER JOIN pg_description des ON (des.objoid=rel.oid AND des.objsubid=0 AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_constraint con ON con.conrelid=rel.oid AND con.contype='p' diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/view.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/view.sql index 279e6ee..259b2de 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/view.sql +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/view.sql @@ -4,11 +4,12 @@ {% set view_icon = "icon-view" if node_type == 'v' else "icon-mview" %} SELECT c.relname AS name, + nsp.nspname AS nspname, '{{ ntype }}' AS object_type, - '{{ view_icon }}' AS icon, - '{{ nspname }}' AS nspname + '{{ view_icon }}' AS icon FROM pg_class c +JOIN pg_namespace nsp ON nsp.oid=c.relnamespace LEFT OUTER JOIN pg_tablespace spc ON spc.oid=c.reltablespace LEFT OUTER JOIN pg_description des ON (des.objoid=c.oid and des.objsubid=0 AND des.classoid='pg_class'::regclass) LEFT OUTER JOIN pg_class tst ON tst.oid = c.reltoastrelid