Ensure the grant wizard works with objects with special characters in the name. Fixes #1599

This commit is contained in:
Surinder Kumar 2016-10-21 11:58:31 +01:00 committed by Dave Page
parent 76fb831554
commit 9155c2111f
9 changed files with 35 additions and 30 deletions

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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'

View File

@ -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