Ensure that Grant Wizard should include foreign tables. Fixes #5959

This commit is contained in:
Nikhil Mohite 2020-11-09 12:44:00 +05:30 committed by Akshay Joshi
parent 3a38f6b147
commit 64964f82cf
9 changed files with 99 additions and 0 deletions

View File

@ -35,3 +35,4 @@ Bug fixes
| `Issue #5923 <https://redmine.postgresql.org/issues/5923>`_ - Fixed an issue where non-closeable tabs are getting closed.
| `Issue #5950 <https://redmine.postgresql.org/issues/5950>`_ - Fixed an issue where a long file name is not visible on the process watcher dialog.
| `Issue #5953 <https://redmine.postgresql.org/issues/5953>`_ - Fixed an issue where connection to the server is on wait state if a different user is provided.
| `Issue #5959 <https://redmine.postgresql.org/issues/5959>`_ - Ensure that Grant Wizard should include foreign tables.

View File

@ -243,6 +243,13 @@ def _get_rows_for_type(conn, ntype, server_prop, node_id):
node_id=node_id, node_type='m')
status, res = conn.execute_dict(sql)
# Fetch Foreign tables.
elif ntype in ['foreign_table']:
sql = render_template("/".join(
[server_prop['template_path'], '/sql/foreign_table.sql']),
node_id=node_id, node_type='m')
status, res = conn.execute_dict(sql)
return status, res
@ -327,6 +334,10 @@ def properties(sid, did, node_id, node_type):
status, res = _get_rows_for_type(
conn, 'mview', server_prop, node_id)
_append_rows(status, res, 'materialized view')
status, res = _get_rows_for_type(
conn, 'foreign_table', server_prop, node_id)
_append_rows(status, res, 'foreign table')
else:
status, res = _get_rows_for_type(conn, ntype, server_prop, node_id)
_append_rows(status, res, 'function')
@ -386,6 +397,10 @@ def msql(sid, did):
data['acl'],
acls['table']['acl'])
data['priv']['foreign_table'] = parse_priv_to_db(
data['acl'],
acls['foreign_table']['acl'])
# Pass database objects and get SQL for privileges
sql_data = ''
data_func = {'objects': data['objects'],
@ -414,6 +429,15 @@ def msql(sid, did):
if sql and sql.strip('\n') != '':
sql_data += sql
data_table = {'objects': data['objects'],
'priv': data['priv']['foreign_table']}
sql = render_template(
"/".join([server_prop['template_path'],
'/sql/grant_foreign_table.sql']),
data=data_table, conn=conn)
if sql and sql.strip('\n') != '':
sql_data += sql
res = {'data': sql_data}
return ajax_response(
@ -473,6 +497,10 @@ def save(sid, did):
data['acl'],
acls['table']['acl'])
data['priv']['foreign_table'] = parse_priv_to_db(
data['acl'],
acls['foreign_table']['acl'])
# Pass database objects and get SQL for privileges
# Pass database objects and get SQL for privileges
sql_data = ''
@ -502,6 +530,15 @@ def save(sid, did):
if sql and sql.strip('\n') != '':
sql_data += sql
data_table = {'objects': data['objects'],
'priv': data['priv']['foreign_table']}
sql = render_template(
"/".join([server_prop['template_path'],
'/sql/grant_foreign_table.sql']),
data=data_table, conn=conn)
if sql and sql.strip('\n') != '':
sql_data += sql
status, res = conn.execute_dict(sql_data)
if not status:
return internal_server_error(errormsg=res)

View File

@ -539,6 +539,9 @@ define([
case 'Materialized View':
object_type = 'table';
break;
case 'Foreign Table':
object_type = 'foreign_table';
break;
default:
break;
}

View File

@ -15,6 +15,10 @@
"type": "TABLE",
"acl": ["a", "r", "w", "d", "D", "x", "t"]
},
"foreign_table": {
"type": "FOREIGN TABLE",
"acl": ["a", "r", "w","x"]
},
"sequence": {
"type": "SEQUENCE",
"acl": ["r", "w", "U"]

View File

@ -0,0 +1,16 @@
{# ===== Fetch list of Database object types(Tables) ===== #}
{% if node_id %}
SELECT
rel.relname AS name,
nsp.nspname AS nspname,
'Foreign Table' AS object_type,
'icon-coll-foreign_table' AS icon
FROM
pg_class rel
JOIN pg_namespace nsp ON nsp.oid=rel.relnamespace
WHERE
rel.relkind IN ('f') AND rel.relnamespace = {{ node_id }}::oid
ORDER BY
rel.relname
{% endif %}

View File

@ -0,0 +1,9 @@
{# ===== Grant Permissions on Database Objects Selected ==== #}
{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
{% for obj in data.objects -%}
{% for priv in data.priv -%}
{% if obj.object_type == 'Foreign Table' %}
{{ PRIVILEGE.SET(conn, 'TABLE', priv['grantee'], obj.name, priv['without_grant'], priv['with_grant'], obj.nspname ) }}
{% endif %}
{% endfor -%}
{% endfor -%}

View File

@ -15,6 +15,10 @@
"type": "TABLE",
"acl": ["a", "r", "w", "d", "D", "x", "t"]
},
"foreign_table": {
"type": "FOREIGN TABLE",
"acl": ["a", "r", "w","x"]
},
"sequence": {
"type": "SEQUENCE",
"acl": ["r", "w", "U"]

View File

@ -0,0 +1,16 @@
{# ===== Fetch list of Database object types(Tables) ===== #}
{% if node_id %}
SELECT
rel.relname AS name,
nsp.nspname AS nspname,
'Foreign Table' AS object_type,
'icon-coll-foreign_table' AS icon
FROM
pg_class rel
JOIN pg_namespace nsp ON nsp.oid=rel.relnamespace
WHERE
rel.relkind IN ('f') AND rel.relnamespace = {{ node_id }}::oid
ORDER BY
rel.relname
{% endif %}

View File

@ -0,0 +1,9 @@
{# ===== Grant Permissions on Database Objects Selected ==== #}
{% import 'macros/schemas/privilege.macros' as PRIVILEGE %}
{% for obj in data.objects -%}
{% for priv in data.priv -%}
{% if obj.object_type == 'Foreign Table' %}
{{ PRIVILEGE.SET(conn, 'TABLE', priv['grantee'], obj.name, priv['without_grant'], priv['with_grant'], obj.nspname ) }}
{% endif %}
{% endfor -%}
{% endfor -%}