diff --git a/web/pgadmin/tools/grant_wizard/__init__.py b/web/pgadmin/tools/grant_wizard/__init__.py index 5c8687b..f3f7828 100644 --- a/web/pgadmin/tools/grant_wizard/__init__.py +++ b/web/pgadmin/tools/grant_wizard/__init__.py @@ -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) diff --git a/web/pgadmin/tools/grant_wizard/static/js/grant_wizard.js b/web/pgadmin/tools/grant_wizard/static/js/grant_wizard.js index 726b118..40f7c00 100644 --- a/web/pgadmin/tools/grant_wizard/static/js/grant_wizard.js +++ b/web/pgadmin/tools/grant_wizard/static/js/grant_wizard.js @@ -539,6 +539,9 @@ define([ case 'Materialized View': object_type = 'table'; break; + case 'Foreign Table': + object_type = 'foreign_table'; + break; default: break; } diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/acl.json b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/acl.json index 2ea34c4..6c9a5fe 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/acl.json +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/acl.json @@ -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"] diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/foreign_table.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/foreign_table.sql new file mode 100644 index 0000000..dc024f0 --- /dev/null +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/foreign_table.sql @@ -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 %} diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/grant_foreign_table.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/grant_foreign_table.sql new file mode 100644 index 0000000..6effc73 --- /dev/null +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/pg/9.1_plus/sql/grant_foreign_table.sql @@ -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 -%} diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/acl.json b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/acl.json index 2ea34c4..6c9a5fe 100644 --- a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/acl.json +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/acl.json @@ -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"] diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/foreign_table.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/foreign_table.sql new file mode 100644 index 0000000..dc024f0 --- /dev/null +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/foreign_table.sql @@ -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 %} diff --git a/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/grant_foreign_table.sql b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/grant_foreign_table.sql new file mode 100644 index 0000000..6effc73 --- /dev/null +++ b/web/pgadmin/tools/grant_wizard/templates/grant_wizard/ppas/9.1_plus/sql/grant_foreign_table.sql @@ -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 -%}